package org.hako.recite.word.gui.swing;

import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.JFrame;

/**
 * Abstract class of frame.
 * 
 * @since 0.4.6
 * @author <a href="mailto:xnnyygn@gmail.com">xnnyygn</a>
 */
public abstract class AbstractReciteWordFrame {

	protected JFrame frame;

	/**
	 * Create
	 * 
	 * @param title
	 * @see JFrame#JFrame(String)
	 */
	public AbstractReciteWordFrame(String title) {
		super();
		frame = new JFrame(title);
	}

	/**
	 * Exit program when click close.
	 * 
	 * @see JFrame#setDefaultCloseOperation(int)
	 * @see JFrame#EXIT_ON_CLOSE
	 */
	public void exitOnClose() {
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	/**
	 * Show window.
	 * 
	 * @see JFrame#setVisible(boolean)
	 */
	public void show() {
		frame.setVisible(true);
	}

	/**
	 * Hide frame.
	 * 
	 * @see JFrame#setVisible(boolean)
	 */
	public void hide() {
		frame.setVisible(false);
	}

	/**
	 * Center current frame in the screen.
	 */
	public void centerInScreen() {
		Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
		int left = (int) ((dimension.getWidth() - frame.getWidth()) / 2);
		int top = (int) ((dimension.getHeight() - frame.getHeight()) / 2);
		frame.setLocation(left, top);
	}

}
